
package com.insigma.business.qrcode.soldier.service.impl;



import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.soldier.dao.PlacementSoldierAspirationResultDao;
import com.insigma.business.qrcode.soldier.dto.PlacementSoldierAspirationResultBSearcher;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.entity.PlacementSoldierAspirationResultDO;
import com.insigma.business.qrcode.soldier.entity.PlacementSoldierInfoDO;
import com.insigma.business.qrcode.soldier.service.PlacementSoldierAspirationResultService;
import com.insigma.business.qrcode.soldier.service.PlacementSoldierInfoService;
import com.insigma.business.qrcode.soldier.util.MiniCacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("placementSoldierAspirationResultService")
public class PlacementSoldierAspirationResultServiceImpl implements PlacementSoldierAspirationResultService {

    @Autowired(required = false)
    private PlacementSoldierAspirationResultDao placementSoldierAspirationResultDao;

    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    @Autowired
    private MiniCacheUtils miniCacheUtils;

    @Autowired
    private PlacementSoldierInfoService placementSoldierInfoService;
    
    @Override
    public List<PlacementSoldierAspirationResultDO> search(final PlacementSoldierAspirationResultBSearcher placementSoldierAspirationResultBSearcher) {
        return placementSoldierAspirationResultDao.search(placementSoldierAspirationResultBSearcher);
    }
   
    @Override
    public PlacementSoldierAspirationResultDO get(final String id){
        return placementSoldierAspirationResultDao.get(id);
    }

    
    @Override
    public Integer insert(final PlacementSoldierAspirationResultDO placementSoldierAspirationResultDO){
        String idCardNo = placementSoldierAspirationResultDO.getIdCardNo();

        String positionId = placementSoldierAspirationResultDO.getPositionId();
        String name = miniCacheUtils.getCachedPlacementPositionName(positionId);
        String batchId = placementSoldierAspirationResultDO.getBatchId();
        String batchType = miniCacheUtils.getCachedBatchType(batchId);

        PlacementSoldierInfoDO soldierInfo = placementSoldierInfoService.getByIdCardNo(idCardNo);
        soldierInfo.setPlacementPositionId(positionId);
        soldierInfo.setPlacementPosition(name);
        soldierInfo.setPlacementType(batchType);
        placementSoldierInfoService.update(soldierInfo);

        placementSoldierAspirationResultDO.setId(sequenceGenerator.genKey(SequenceNameConstant.PLACEMENT_SOLDIER_ASPIRATION_RESULT_ID));
        return placementSoldierAspirationResultDao.insert(placementSoldierAspirationResultDO);
    }

    
    @Override
    public Integer update(final PlacementSoldierAspirationResultDO placementSoldierAspirationResultDO){
        return placementSoldierAspirationResultDao.update(placementSoldierAspirationResultDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return placementSoldierAspirationResultDao.delete(id,modifierType,modifierId);
    }

    @Override
    public Integer countByPositionId(String positionId) {
        return placementSoldierAspirationResultDao.countByPositionId(positionId);
    }

    @Override
    public PlacementSoldierAspirationResultDO getBySoldierId(String soldierId) {
        String idCardNo = placementSoldierInfoService.getIdCardNoBySoldierId(soldierId);
        return placementSoldierAspirationResultDao.getByIdCardNo(idCardNo);
    }

    @Override
    public PlacementSoldierAspirationResultDO getByIdCardNo(String idCardNo) {
        return placementSoldierAspirationResultDao.getByIdCardNo(idCardNo);
    }

    @Override
    public List<PlacementSoldierAspirationResultDO> listByBatchId(String batchId) {
        return placementSoldierAspirationResultDao.listByBatchId(batchId);
    }

    @Override
    public Boolean isRecruited(String idCardNo) {
        int i = placementSoldierAspirationResultDao.countByIdCardNo(idCardNo);
        return i > 0;
    }

    @Override
    public Integer deleteByPositionId(String positionId, String modifierType, String modifierId) {
        return placementSoldierAspirationResultDao.deleteByPositionId(positionId, modifierType, modifierId);
    }


}
